﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_AddMoney : System.Web.UI.Page
{
    BankDataDataContext db = new BankDataDataContext();

    protected void Page_Load(object sender, EventArgs e)
    {
        BankAccount account = getBankAccount();
        if (account != null)
        {
            CurrencyLabel.Text = account.Currency.Name;
        }
    }

    protected void AddButton_Click(object sender, EventArgs e)
    {
        decimal money = Convert.ToDecimal(Money.Text);
        BankAccount account = getBankAccount();
        if (account != null)
        {
            account.Amount += money;
            db.SubmitChanges();
        }
        Session.Remove("bankAccountId");
        Response.Redirect("~/Admin/BankAccounts.aspx");
    }

    protected string getBankAccountId()
    {
        string id = null;
        if (Session["bankAccountId"] != null)
        {
            id = Session["bankAccountId"].ToString();
        }
        return id;
    }

    protected BankAccount getBankAccount()
    {
        string id = getBankAccountId();
        if (id != null)
        {
            var bas = from ba in db.BankAccounts where ba.BankAccountId == Convert.ToInt32(id) select ba;
            if (bas.Count() > 0)
            {
                return bas.First();
            }
        }
        return null;
    }
}